package com.hewl.aop;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class SysLogAspect {
	 private static Logger logger = LoggerFactory.getLogger(SysLogAspect.class);
	
	@Pointcut("execution(* com.hewl.shiro.admin.controller.*.*(..))")
	private void logCtrlAspect() {
		
	}

	
	@Before("logCtrlAspect()")
	private void logCtrlBefore() {
		logger.info("aspect @Before");
	}
	
	@After("logCtrlAspect()")
	private void logCtrlAfter() {
		logger.info("aspect @After");
	}
	
	@AfterReturning(pointcut = "logCtrlAspect()", returning = "retVal")
	private void logCtrlDoAfter(Object retVal) {
		logger.info("aspect @AfterReturning");
	}
	
	@AfterThrowing(value = "logCtrlAspect()", throwing = "ex")
	private void logCtrlThrowing(Throwable ex) {
		logger.info("aspect @AfterThrowing");
	}
	
	
	public static boolean isAjax(HttpServletRequest request) {
		return (request.getHeader("X-Requested-With") != null && "XMLHttpRequest".equals(request.getHeader("X-Requested-With").toString()));
	}
}
